package hackathon.light.up;

import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Bitmap;
import android.graphics.Color;

import com.e3roid.E3Activity;
import com.e3roid.E3Engine;
import com.e3roid.E3Scene;
import com.e3roid.drawable.Background;
import com.e3roid.drawable.Drawable;
import com.e3roid.drawable.Shape;
import com.e3roid.drawable.texture.AssetTexture;
import com.e3roid.drawable.texture.Texture;
import com.e3roid.event.FrameListener;
import com.e3roid.event.SceneUpdateListener;
import com.e3roid.util.BitmapUtil;
import com.e3roid.util.Debug;

public class MainActivity extends E3Activity{

	private static int WIDTH  = 320;
	private static int HEIGHT = 480;

	
	private Grid grid;
	private Light light,l2,l1;
	private LightSource source1;
	public static SceneUpdateListener listener;
	
	@Override
	public E3Engine onLoadEngine() {
		HEIGHT = this.getWindowManager().getDefaultDisplay().getHeight();
		WIDTH = this.getWindowManager().getDefaultDisplay().getWidth();
		
		E3Engine engine = new E3Engine(this, WIDTH, HEIGHT);
		engine.requestFullScreen();
		engine.requestPortrait();
		return engine;
	}

	@Override
	public E3Scene onLoadScene() {
		E3Scene scene = new E3Scene();
		listener = new SceneUpdateListener() {
			
			@Override
			public void onUpdateScene(E3Scene arg0, long arg1) {
				// TODO Auto-generated method stub
				grid.update(arg0);
				arg0.unregisterUpdateListener(listener);
			}
		};
		
		//scene.registerUpdateListener(16, listener);
		
		//scene.getTopLayer().add(light.getShape());
		//scene.getTopLayer().add(l1.getShape());
		//scene.getTopLayer().add(l2.getShape());
		//scene.getTopLayer().add(source1.getShape());
		
		grid.update(scene);
		// load tile with 32x32, tile no.3, 1px border
		scene.setBackgroundColor(0, 0, 0, 255);
		Debug.d("onLoadScene");
		return scene;
	}
	
	@Override
	public void onLoadResources() {
		Element.robotTexture = new AssetTexture("robot.png", this);
		grid = new Grid(WIDTH,HEIGHT,10,6,2,20);
		//light = new Light(3,3, 0, 0,3, 1);
		//source1 = new LightSource(3, 1, LightDirection.E, 4);
		//light = new Light(3,  0 , 0,3,3, 1);
		
		//l1 = new Light(3,3, 0, 3,3, 2);
		//l2 = new Light(3,0, 0, 0,3, 4);
		Debug.d("onLoadResource");
		
	}
	
	
	
	public Shape createLine(int x,int y,int w,int h,float r, float b, float g, float a) {
		
		Shape s = new Shape(x, y, w, h);
		s.setColor(r, g, b,a);
		return s;
	}

}
